package com.grf.hadoop.sort;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.Partitioner;
import org.apache.hadoop.mapreduce.RecordReader;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;

import java.io.IOException;

public class FlowPartitioner extends Partitioner<FlowBean, Text> {

    @Override
    public int getPartition(FlowBean flowBean, Text value, int i) {

        int partition = 4;
        String prePhoneNum = value.toString().substring(0,3);

        if (prePhoneNum.equals("136")) {
            partition = 0;
        } else if(prePhoneNum.equals("137")) {
            partition = 1;
        } else if(prePhoneNum.equals("138")){
            partition = 2;
        } else {
            partition =3;
        }


        return partition;
    }
}
